<?php

declare(strict_types=1);

namespace App\Command;

use App\Model\Dao\MchAccountDao;
use App\Model\Dao\TradeOrderDetailDao;
use App\Service\RepairService;
use App\Utils\RedisUtils;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Symfony\Component\Console\Input\InputArgument;
use Psr\Container\ContainerInterface;
use Hyperf\Di\Annotation\Inject;

use App\Service\TestService;
use App\Utils\CustomUtils;
use Symfony\Component\Console\Input\InputOption;

/**
 * @Command
 */
class RepairCommand extends HyperfCommand
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    /**
     * 执行的命令行
     *
     * @var string
     */
    protected $name = 'settle:repair';

    /**
     * @Inject()
     * @var RepairService
     */
    private $RepairService;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
        parent::__construct();
    }

    public function configure()
    {
        parent::configure();
        $this->setHelp('修复命令');
        $this->addOption('type','t', InputOption::VALUE_OPTIONAL, '修复类型');
        $this->addOption('extra','e', InputOption::VALUE_OPTIONAL, '扩展数据，格式：id:1|handleStatus:1|statMonth:2021-02');
    }

    public function handle()
    {
        $options = $this->input->getOptions();
        CustomUtils::xzxDebug($options);
        if (!isset($options['type']) || empty($options['type'])) {
            $this->line("请输入type参数");
            return;
        }

        $type = $options['type'];
        $extraStr = !empty($options['extra']) ? $options['extra'] : '';
        $extra = [];
        if (!empty($extraStr)) {
            $tmp = explode('|', $extraStr);
            foreach ($tmp as $value) {
                $item = explode('=', $value);
                $extra[$item[0]] = $item[1];
            }
        }

        $this->RepairService->handle([
            'type'  => $type,
            'extra' => $extra
        ]);
    }


}
